package guij.controller;

import guij.dao.mapper.ItemMapper;
import guij.taobao.TaobaokeInterface;
import guij.taobao.TopInterface;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.taobao.api.model.Item;

public class GetItems implements Controller{

	@Override
	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		String sessionkey = arg0.getSession().getAttribute("sessionkey").toString();
		int num = 30;
		List<Item> items = topInterface.getOnSaleItems(sessionkey,num, null);
		
		String nikc = arg0.getSession().getAttribute("nick").toString();

		List<Item> rssItems = itemMapper.selectByNick(nikc);
		
		Map<String,List<Item>> ret = new HashMap();
		ret.put("rssItems",rssItems);
		ret.put("items",items);
		
		return new ModelAndView(getViewPage(),ret);
		}
	
	public void setTopInterface(TopInterface topInterface) {
		this.topInterface = topInterface;
	}
	public TopInterface getTopInterface() {
		return topInterface;
	}
	/**
	 * @param taobaokeInterface the taobaokeInterface to set
	 */
	public void setTaobaokeInterface(TaobaokeInterface taobaokeInterface) {
		this.taobaokeInterface = taobaokeInterface;
	}
	/**
	 * @return the taobaokeInterface
	 */
	public TaobaokeInterface getTaobaokeInterface() {
		return taobaokeInterface;
	}
	public void setViewPage(String viewPage) {
		this.viewPage = viewPage;
	}
	public String getViewPage() {
		return viewPage;
	}
	
	private TaobaokeInterface taobaokeInterface;
	
	private TopInterface topInterface;
	private ItemMapper itemMapper;
	
	private String viewPage;
}
